package com.ruoyi.project.remake.controller.api;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.remake.domain.TCaseMain;
import com.ruoyi.project.remake.domain.TRemakeCaseDetails;
import com.ruoyi.project.remake.domain.dto.CopyCaseDto;
import com.ruoyi.project.remake.domain.query.SelfMachine;
import com.ruoyi.project.remake.domain.vo.CaseMainVo;
import com.ruoyi.project.remake.domain.vo.CopyCaseVo;
import com.ruoyi.project.remake.service.ITApplyStatusService;
import com.ruoyi.project.remake.service.ITCaseMainService;
import com.ruoyi.project.remake.service.ITRemakeCaseDetailsService;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@Api("自助机模块")
@RestController
@RequestMapping("/api/remaked/selfService")
public class SelfMachineController extends BaseController {


    @Autowired
    private ITApplyStatusService tApplyStatusService;

    @Autowired
    private ITCaseMainService tCaseMainService;

    @Autowired
    private ITRemakeCaseDetailsService tRemakeCaseDetailsService;
    @Autowired
    private ISysDictDataService dictDataService;
    /**
     * 自助机申请打印病例
     * @param selfMachine
     * @return
     */
    @ApiOperation("自助机申请打印病例")
    @GetMapping("/selfApply")
    public AjaxResult selfApply(SelfMachine selfMachine)
    {
        tApplyStatusService.seflApply(selfMachine);
        return AjaxResult.success();
    }


    /**
     * 自助机申请病例
     * @param selfMachine
     * @return
     */
    @ApiOperation("申请病例")
    @GetMapping("/queryList")
    public AjaxResult queryByCard(SelfMachine selfMachine)
    {
        TCaseMain tCaseMain=new TCaseMain();
        tCaseMain.setCardId(selfMachine.getCardId());
        tCaseMain.setMedicalCardId(selfMachine.getMedicalCardId());
        List<TCaseMain> list = tCaseMainService.selectSelfFrontList(tCaseMain);
        return AjaxResult.success(list);
    }
    /**
     * 自助机病例详情
     * @param id
     * @return
     */
    @ApiOperation("病例打印详情")
    @GetMapping("/print/{id}")
    public AjaxResult list(@PathVariable Long  id)
    {
        List<TRemakeCaseDetails> result = tRemakeCaseDetailsService.remakeDetails(id,null);
        return AjaxResult.success(result);
    }

    /**
     * 病例打印回调
     * @param id
     * @return
     */
    @ApiOperation("病例打印回调")
    @GetMapping("/PrintCallback/{id}")
    public AjaxResult PrintCallback(@PathVariable Long  id)
    {
        CaseMainVo tCaseMain=tCaseMainService.selectTCaseMainById(id);
        TCaseMain caseMain=new TCaseMain();
        caseMain.setPrintNumber(null==tCaseMain.getPrintNumber()?1:tCaseMain.getPrintNumber()+1);
        caseMain.setId(tCaseMain.getId());
        tCaseMainService.updateTCaseMain(caseMain);
        return AjaxResult.success();
    }
    /**
     * 病例打印 2022-06-08 需求调整
     * @param id
     * @return
     */
    @ApiOperation("病例打印")
    @GetMapping("/printList/{id}/{ids}")
    public AjaxResult printList(@PathVariable Long  id,@PathVariable String ids)
    {
        List<TRemakeCaseDetails> result = tRemakeCaseDetailsService.remakeDetails(id,null,ids);
        return AjaxResult.success(result);
    }
    /**
     * type
     * @return
     */
    @ApiOperation("可以打印的病例分类")
    @GetMapping("/print/type")
    public AjaxResult typeList()
    {
        SysDictData dictData = new SysDictData();
        dictData.setDictType(Constants.CASE_CLASS);
        dictData.setRemark("1");
        List<SysDictData> sysDictDataList= dictDataService.selectDictDataList(dictData);
        return AjaxResult.success(sysDictDataList);
    }
}
